
import Cfg from './config.js';
import Msg from './message.js';
const EFFECT_IN = ['none','slide-in-right','slide-in-left','slide-in-top','slide-in-bottom','pop-in','fade-in','zoom-out','zoom-fade-out'];
const EFFECT_OUT = ['none','slide-out-right','slide-out-left','slide-out-top','slide-out-bottom','pop-out','fade-out','zoom-in','zoom-fade-in'];
//通用跳转
const navTo = (param) =>{
	//console.log(param)
	let url = Cfg.getParam(param,'url','');
	let type = Cfg.getParam(param,'type',0);
	let ani_type = 'none';	
	if(Cfg.Setting.effect_on){
		let index = Math.floor(Math.random()*(EFFECT_IN.length+1));
		ani_type = EFFECT_IN[index]; 
	}		
	if(!url.has){
		Msg.Fail('navTo函数传入参数有问题，请检查！');
		return false;		
	}
	if(url.value.substr(0,1)!='/')url.value='/'+url.value;	
	//console.log(type.value)
	switch(type.value){
		case 0://不关本页到目的页
		   // console.log(type.value)
			uni.navigateTo({url:url.value,animationType:ani_type,fail:(e)=>{
				console.log(e)
			}});
			//console.log(0)
			break;
		case 1://关闭当前页到目的页
		//console.log(ani_type)			
			uni.redirectTo({url:url.value,animationType:ani_type});
			//console.log(1)
			break;
		case 2://关闭所有页到目的页
			uni.switchTab({url:url.value,animationType:ani_type})
			break;
		default:
			uni.navigateTo({url:url.value,animationType:ani_type});	
	}
}

const goPage = (e) => {
	let url = e.currentTarget.dataset["url"];
	if(url!=''&&url!=null)navTo({url:url});	
}


module.exports = {    
	_to:navTo,
	goPage:goPage
}